﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data.EntityClient;

namespace AppManagement.Helpers
{
    #region Using
    using AppManagement.Models;
    #endregion

    public class GlobalVars
    {
        public static string g_strPathConfig = "D:\\app_config.xml";
        public static string g_strDataSource;
        public static string g_strDataBaseName;
        public static NguoiDung g_CurrentUser;
        public static string g_strEntityConnectionString;

        public static string BuildEntityConnectionString()
        {
            string providerName = "System.Data.SqlClient";
            string serverName = g_strDataSource;
            string databaseName = g_strDataBaseName;

            // Initialize the connection string builder for the
            // underlying provider.
            SqlConnectionStringBuilder sqlBuilder =
                new SqlConnectionStringBuilder();

            // Set the properties for the data source.
            sqlBuilder.DataSource = serverName;
            sqlBuilder.InitialCatalog = databaseName;
            sqlBuilder.IntegratedSecurity = true;

            // Build the SqlConnection connection string.
            string providerString = sqlBuilder.ToString();

            // Initialize the EntityConnectionStringBuilder.
            EntityConnectionStringBuilder entityBuilder =
                new EntityConnectionStringBuilder();

            //Set the provider name.
            entityBuilder.Provider = providerName;

            // Set the provider-specific connection string.
            entityBuilder.ProviderConnectionString = providerString;

            // Set the Metadata location.
            entityBuilder.Metadata = @"res://*/Models.DataModels.csdl|res://*/Models.DataModels.ssdl|res://*/Models.DataModels.msl";

            return entityBuilder.ToString();
        }
    }
}
